const mongoose = require('./db')
//用户
const userSchema = new mongoose.Schema({
    user: {
        type: String,
        require: true,
    },      //账号
    pwd: {
        default: '123456',
        type: String,
    },      //密码
    phone: {
        type: String,
        require: String
    },      //手机号
    role: mongoose.Types.ObjectId
})

//角色
const roleSchema = new mongoose.Schema({
    title: {
        type: String,
        require: true
    },   //角色名称
    menusId: [mongoose.Types.ObjectId]   //角色权限
})

//路由
const menusSchema = new mongoose.Schema({
    url: String,     //路径
    title: String,   //标题
    icon: String,    //图标  
    level: Number,   //路由等级
    uid: {
        ref: 'menus',
        type: mongoose.Types.ObjectId
    } //路由id
})


//导出模型
const userModel = mongoose.model('user', userSchema, 'user')
const roleModel = mongoose.model('role', roleSchema, 'role')
const menusModel = mongoose.model('menus', menusSchema, 'menus')
module.exports = {
    userModel,
    roleModel,
    menusModel
}
